<template>
	<view class="myArticle-wrap">
		<view class="index-article" v-if="articleList.length > 0">
			<u-title :value="status == 0 ? '我的草稿' : '我的文章'"></u-title>
			<view class="index-article-scroll ">
				<u-article-item
					v-for="(item, index) in articleList"
					:key="index"
					:data="item"
					type="1"
					@clickOne="deleteArticle(item.id)"
					@clickTwo="gotoRouter('/pages-doctor/editArticle/editArticle?id=' + item.id)"
				></u-article-item>
			</view>
		</view>

		<u-empty-state v-if="dataList.length == 0" :value="status == 0 ? '草稿箱空空如也' : '您还没有文章'" type="1"></u-empty-state>
	</view>
</template>

<script>
import uArticleItem from '@/components/u-article-item/u-article-item.vue';
import uTitle from '@/components/u-title/u-title.vue';
export default {
	components: {
		uArticleItem,
		uTitle
	},
	data() {
		return {
			status: 0,
			articleList: []
		};
	},
	onLoad(option) {
		this.status = option.status;
		
	},
	onShow() {
		this.myArticleList();
	},
	onReady(){
		uni.setNavigationBarTitle({
		    title: this.status == 0 ? '我的草稿' : '我的文章'
		});
	},
	methods: {
		//文章列表
		myArticleList() {
			this.$api
				.myArticleList({
					params: {
						status: this.status,
						pageSize: 999
					}
				})
				.then(res => {
					if (res.code == 200) {
						this.articleList = res.result.records;
					} else {
						uni.showToast({
							title: res.message,
							icon: 'none'
						});
					}
				});
		},

		//删除文章
		deleteArticle(id) {
			uni.showModal({
				title: `确认要删除文章吗？`,
				success: res => {
					if (res.confirm) {
						this.$api
							.deleteArticle({
								params: {
									id: id
								}
							})
							.then(res => {
								if (res.code == 200) {
									uni.showToast({
										title: `删除成功`,
										icon: 'none'
									});
									this.myArticleList();
								} else {
									uni.showToast({
										title: res.message,
										icon: 'none'
									});
								}
							});
					}
				}
			});
		}
	}
};
</script>

<style lang="less">
@import './myArticle.less';
</style>
